
<?php

include "database_functions.inc.php";


function get_customer_list()
{
  $all_query = "SELECT cus_id FROM customer";
  $rs = query($all_query);
  $found = array();
  while ($row = mysql_fetch_object($rs)) {
    $found[] = get_customer_info($row->cus_id);
  }
  return $found;
}

function get_customer_info($cus_id)
{
  $query_cus = sprintf("SELECT * FROM customer WHERE cus_id = %d", $cus_id);
  $rs = query($query_cus);
  $row = mysql_fetch_object($rs);

  $found = array(
		 'id' => $row->cus_id,
		 'card' => $row->cus_card,
		 'first_name' => $row->cus_first_name,
		 'last_name' => $row->cus_last_name,
		 'birth' => $row->cus_birth,
		 'email' => $row->cus_email,
		 'phone' => $row->cus_phone,
		 'reg_date' => $row->cus_reg_date,
		 'password' => $row->cus_password,
		 'address' => $row->cus_address,
		 'username' => $row->cus_username,
		 'gender' => $row->cus_gender
		 );

  return $found;
}


function send_help_request($name, $mail, $note)
{
  $query_request = sprintf("INSERT INTO help_request(req_sender, req_mail, req_note) VALUES('%s', '%s', '%s')", $name, $mail, $note);
  $rs = query($query_request);

  return 0;
}
  
function set_password($ulogin, $upass)
{
  $query_pass = sprintf("UPDATE customer SET cus_password = %s WHERE cus_id = %d", $upass, $ulogin);
  $rs = query($query_pass);

  return 0;
}

function get_password($ulogin)
{
  $query_pass = sprintf("SELECT * FROM customer WHERE cus_id = %d", $ulogin);
  $rs = query($query_pass);
  $row = mysql_fetch_object($rs);

  return $row->cus_password;
}

function authenticate($ulogin, $upass)
{
  $query_login = sprintf("SELECT * FROM customer WHERE cus_username = '%s' AND cus_password = '%s'", $ulogin, $upass);
  $rs = query($query_login);
  if (mysql_num_rows($rs) > 0)
    return 0;
  return 1;
}


?>